package com.chapter1;

import java.util.*;

 class ListNode {
   int val;
   ListNode next = null;
   public ListNode(int val) {
     this.val = val;
   }
  }

public class test2 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param a ListNode类一维数组 指向这些数链的开头
     * @return ListNode类
     */
    public ListNode solve (ListNode[] a) {
        // write code here
        ListNode ans = new ListNode(0);
        ListNode temp = ans;
        while(true){
            int num = 0;
            for(int i = 0; i < a.length; i++){
                if(a[i] != null){
                    num++;
                    temp.next = a[i];
                    temp = temp.next;
                    a[i] = a[i].next;
                }
            }
            if(num == 0){
                break;
            }
        }
        return ans.next;
    }
}
